<template>
    <view>
            <view class="tabbar">
                <view class="item" v-for="(item,index) in tabbar":key='index' @tap="tabbar_click(index)">
                    <view class="img">
                        <image :src="item.img_click_src" mode="" v-if="index == currentIndex"></image>
                        <image :src="item.img_src" mode="" v-if="index != currentIndex"></image>
                    </view>
                    <text class="tab-text cur" v-if="index == currentIndex">{{item.name}}</text>
                    <text class="tab-text" v-if="index != currentIndex">{{item.name}}</text>
                </view>
            </view>
        </view>
</template>

<script>
    export default {
        props: {
                    currentIndex: {
                        type: Number,
                        default: 0
                    }
                },
        data() {
            return {
                tabbar: [
                    {
                        img_src: "../static/icon/sc-Tab-icon-01@3x.png",
                        name: "首页",
                        img_click_src: "../static/icon/sc-Tab-icon-Active-01@3x.png",
                        src: "/pages/index/index"
                    }, 
                    {
                        img_src: "../static/icon/sc-Tab-icon-02@3x.png",
                        name: "分类",
                        img_click_src: "../static/icon/sc-Tab-icon-Active-02@3x.png",
                        src: "/pages/list/classify"
                    },
                    // {
                    //     img_src: "../static/icon/sc-Tab-icon-03@3x.png",
                    //     name: "购物车",
                    //     img_click_src: "../static/icon/sc-Tab-icon-Active-03@3x.png",
                    //     src: "/pages/list/cart"
                    // },
                    // {
                    //     img_src: "../static/icon/sc-Tab-icon-04@3x.png",
                    //     name: "用户",
                    //     img_click_src: "../static/icon/sc-Tab-icon-Active-04@3x.png",
                    //     src: "/pages/list/user"
                    // }
                ]
            }
        },
        methods: {
            tabbar_click(e) {
                            uni.redirectTo({
                                url: this.tabbar[e].src
                            })
                }
            }
}

</script>

<style lang="scss">
    .tabbar {
        border-top: 1rpx solid #eee;
        position: fixed;
        left: 0;
        bottom: 0;
        min-height: 50PX;
        width: 100%;
        background-color: #fff;
        display: flex;
        z-index: 99;
        // 计算如iPhoneX等手机底部返回横条的安全距离
        padding-bottom: constant(safe-area-inset-bottom);
        padding-bottom: env(safe-area-inset-bottom); 
        box-sizing: content-box;
        .item {
            flex: 1;
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            align-items: center;
            color: #999;
            height: 50px;
            .img {
                width: 28px;
                height: 28px;
                margin-top: 5rpx;
                image {
                    width: 100%;
                    height: 100%;
                }
            }
            .tab-text {
                display: inline-block;
                width: 100%;
                font-size: 22rpx;
                text-align: center;
                margin-bottom: 10rpx;
            }
        }
    }
    .cur {
        color: #1bc078;
        font-weight: bold;
    }
</style>
